<h1>Perfil</h1>

<div class="actions">
  <%= link_to "Editar", edit_role_path(@role) %>
</div>

<ul>
  <li>Name: <%= @role.name %></li>
  <li>Active: <%= @role.active %></li>
</ul>

<div id="features">
  <h3>Funcionalidades</h3>

  <ul>
    <% @role.features.each do |feature| %>
      <li><%= feature.name %></li>
    <% end %>
  </ul>
</div>

<div id="user_groups">
  <h3>Usuários vinculados</h3>

  <% if @role.group_users.present? %>
    <ul>
      <% @role.group_users.group(:group_id).each do |gu| %>
        <h4>Grupo <%= link_to gu.group.name, gu.group %></h4>
        <% @role.group_users.where(group_id:gu.group_id).each do |group_user|%>      
          <ul>
          <li><%= link_to group_user.user.name, group_user.user %></li>
          </ul>  
        <% end %>
      <% end %>
    </ul>
  <% end %>
</div>

<%= link_to "Voltar", roles_path %>
